package com.mt.baseinfo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RequestMapping(value = "/kafka")
@RestController
public class KafkaProducerController {
    @Autowired
    private KafkaTemplate kafkaTemplate;

    @RequestMapping(value = "/producer", method = RequestMethod.GET)
    public void consume(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            for (int i = 0; i < 100; i++) {
                kafkaTemplate.send("Test", "hello"+i);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
}
